﻿using BLL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Com.Qkds.Erp.WebUi
{
    public partial class ClientList : System.Web.UI.Page
    {
        public int pid
        {
            get
            {
                return int.Parse(ViewState["pid"].ToString());
            }
            set
            {
                ViewState["pid"] = value;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                pid = 0;
                if (Request["id"] != null)
                {
                    string TableName = "Client";
                    pid = int.Parse(Request["ID"].ToString());
                    ClientModel model = new ClientBLL().GetModelByID(TableName, pid);
                    this.txtName.Value = model.Name;
                    this.txtSex.Value = model.Sex;
                    this.TextAddress.Value = model.Address;
                    this.TextCall.Value = model.Call;
                    this.TextAB.Value = model.AB;


                }

            }
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            ClientModel model = new ClientModel()
            {

                Name = this.txtName.Value,
               Sex = this.txtSex.Value,
               Address=this.TextAddress.Value,
               Call=this.TextCall.Value,
               AB=this.TextAB.Value

            };
            ClientBLL bll = new ClientBLL();
            if (pid > 0)
            {
                bll.Gai(model, pid);

            }
            else
            {
                bll.Add(model);


            }
            Response.Redirect("Client.aspx");
        }
    }
}